<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>{eyou:global name='web_name' /}</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
        <link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <!-- 新样式 2020-12-8 -->
        {eyou:static file="users/skin/css/element/index.css" /}
        {eyou:static file="users/skin/userfont/iconfont.css" /}
        {eyou:static file="users/skin/css/e-user.css" /}
        {eyou:include file="users/skin/css/diy_css.htm"/}

        {eyou:static file="/public/static/common/js/jquery.min.js"/}
        {eyou:static file="users/skin/js/vendor.js"/}
        {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
        {eyou:static file="/public/static/common/js/tag_global.js"/}
    </head>

    <body>
        <!--头部--->
         <div class="ey-header-status">
             <div class="header-status-l">
                 <a href="javascript:history.go(-1);"><i class="el-icon-arrow-left"></i></a>
             </div> 
             <div class="header-status-m">收货地址</div> 
             <div class="header-status-r"> </div>
         </div><!--头部 end--->    
         <div class="h50"></div>
        
         <div class="ey-container">
          
            {eyou:eq name='$is_wechat' value='1'}
            <div class="users-info">
                <div class="item-list">
                    <div class="item" onclick="GetWechatData(this);" data-url="{$add_addr_url}">
                        <div class="item-l"><i class="iconfont icon-weixin" style="color:#1fa91f;font-size:20px;"></i></div>
                        <div class="item-m ">获取微信收货地址</div>
                        <div class="item-r"><i class="el-icon-arrow-right"></i></div>
                    </div>
                </div>
            </div>  
            {/eyou:eq}
             <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
             <script type="text/javascript">
                // 获取微信调用接口数据
                function GetWechatData(ey_this) {
                    var wechat_url = $(ey_this).attr('data-url');
                    // layer_loading('正在处理');
                    $.ajax({
                        url: wechat_url,
                        data: {'_ajax': 1},
                        type: 'post',
                        dataType:'json',
                        success:function(res) {
                            layer.closeAll();
                            if (res.code == 1) {
                                GetAddr(res.data);
                            } else {
                                showErrorAlert(res.msg);
                            }
                        },
                        error : function(e) {
                            layer.closeAll();
                            showErrorAlert(e.responseText);
                        }
                    });
                }
        
                function GetAddr(data) {
                    wx.config({
                        appId:     data.appid,
                        timestamp: data.timestamp,
                        nonceStr:  data.noncestr,
                        signature: data.signature,
                        jsApiList: [
                            'checkJsApi',
                            'openAddress',
                            // 'chooseAddress',
                        ]
                    }); 

                    wx.ready(function() {
                        wx.openAddress({
                            success: function (res) {
                                // 地址同步到本地数据库中
                                AddWechatAddress(res);
                            },
                            cancel: function () {
                                // layer.msg('不使用微信地址，请添加本站地址！', {time: 2000});
                            }
                        });
                    });
                }

                function AddWechatAddress(addr) {
                    if (!addr) layer.msg('获取数据错误，请刷新重试~~', {time: 2000});
                    $.ajax({
                        url: "{eyou:url link='user/Shop/add_wechat_addr'/}",
                        data: {
                            userName    :addr.userName,
                            telNumber   :addr.telNumber,
                            provinceName:addr.provinceName,
                            cityName    :addr.cityName,
                            countryName :addr.countryName,
                            detailInfo  :addr.detailInfo,
                        },
                        type:'post',
                        dataType:'json',
                        success:function(res) {
                            if (1 == res.code) {
                                layer.msg(res.msg, {time: 500}, function() {
                                    window.location.href = res.url;
                                });
                            } else {
                                showErrorAlert(res.msg);
                            }
                        }
                    });
                }
             </script>
             
         {eyou:spaddress id="addr" type='add'}
             <div class="address-list" {$addr.UlHtmlId}>
                {eyou:spaddress id="field" type="data"}
                <div class="address-item" {$field.ul_il_id}>
                    {eq name='$type' value='order'}
                        <div class="address-item-t flex align-c">
                            <div class="address-item-tl">
                                <div class="name">
                                    <span {$field.ConsigneeId}>{$field.consignee}</span>
                                    <span {$field.MobileId}>{$field.mobile}</span>
                                    {eyou:eq name='$field.is_default' value='1'}<span class="default">默认</span>{/eyou:eq}
                                </div>
                                <div class="address">
                                    <span {$field.InfoId}>{$field.Info}</span>
                                    <span {$field.AddressId}>{$field.address}</span>
                                 </div>
                            </div>
                            <div class="address-item-tr">
                                <span {$field.ShopEditAddr}><i class="iconfont icon-bianji" style="font-size: 18px;"></i></span>
                            </div>                             
                        </div> 
                    {else /}
                        <div class="address-item-t">
                            <div class="name">
                                <span {$field.ConsigneeId}>{$field.consignee}</span>
                                <span {$field.MobileId}>{$field.mobile}</span>
                            </div>
                            <div class="address">
                                <span {$field.InfoId}>{$field.Info}</span>
                                <span {$field.AddressId}>{$field.address}</span>
                             </div>
                        </div>
                        <div class="address-item-b">
                             <div class="address-item-l flex" {$field.SetDefault}>
                                <span class="pay-select-btn {eyou:eq name='$field.is_default' value='1'} on {/eyou:eq}"></span>
                                <span class="default_text">
                                    {eyou:eq name='$field.is_default' value='1'}
                                        默认地址
                                    {eyou:else/}
                                        设为默认
                                    {/eyou:eq}
                                </span>
                             </div>
                             <div class="address-item-r">
                                 <span {$field.ShopEditAddr}><i class="el-icon-edit-outline"></i>编辑</span>
                                 <span {$field.ShopDelAddr}><i class="el-icon-delete"></i>删除</span>
                             </div>
                        </div>  
                    {/eq}
                </div>
                {/eyou:spaddress}
             </div>
            <div class="h50"></div>
            <div class="address-add">
                <a href="JavaScript:void(0);" {$addr.ShopAddAddr}>新建地址</a>
            </div>
        {$addr.hidden}
        {/eyou:spaddress}
        </div>